package com.lanmon.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="com_user")  
public class ComUser implements Serializable{
	private Integer userid;
	private String username;
	private String uname;
	private String gender;
	private Date birthDate;
	private String address;
	private Organization organization;
	private String password;
	private Integer isvalid;
	
	@GenericGenerator(name = "generator", strategy = "identity")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "userid", unique = true, nullable = false)
	public Integer getUserid() {
		return userid;
	}
	
	public void setUserid(Integer userid) {
		this.userid = userid;
	}
	@Column(name = "username", nullable = false, length = 50) 
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	@Column(name = "password", nullable = false, length = 50) 
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	@Column(name = "isvalid", nullable = false) 
	public Integer getIsvalid() {
		return isvalid;
	}
	
	public void setIsvalid(Integer isvalid) {
		this.isvalid = isvalid;
	}
	@Column(name = "u_name", nullable = false) 
	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}
	@Column(name = "gender")
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	
	@Column(name = "birth_date")
	//@JsonSerialize(using=CustomDateConverter.class)
	@Temporal(TemporalType.DATE)
	public Date getBirthDate() {
		return birthDate;
	}
	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}
	@Column(name = "address")
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	@OneToOne(fetch=FetchType.LAZY)  
	@JoinColumn(name="orgid")  
	public Organization getOrganization() {
		return organization;
	}
	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	@Override
	public String toString() {
		return "ComUser [userid=" + userid + ", username=" + username + ", uname=" + uname + ", gender=" + gender + ", birthDate=" + birthDate + ", address=" + address
				+ ", organization=" + organization==null?"":organization.getOrgname() + ", password=" + password + ", isvalid=" + isvalid + "]";
	}
}
